const mysql = require('mysql');
const database = require('../config/datebase');


const pool = mysql.createPool(database);

// let query = (sql, options, callback) => {
//     pool.getConnection( (err, conn)=> {
//         if(err){
//             callback(err)
//         }
//     } )
// }

let query = (sql,options) =>{
    return new Promise((resolve, reject)=>{
        pool.getConnection((err, conn)=>{
            if(err){
                reject(err);
            }else{
                conn.query(sql,options, (err, results, fields)=>{
                    conn.release();  // 释放连接
                    if(err){
                        reject(err);
                    }else{
                        resolve(results);
                    }
                } )
            }
        })
    })
}

module.exports = query;